<?

class render
{
	public static $types = array(
		'text/html' => 'html',
		'application/json' => 'json',
	);

	public static function action( action_controller $action )
	{
		if ( !$action->get_renderer() ) return;

		$class = 'render_' . $action->get_renderer();
		return call_user_func("{$class}::action", $action);
	}

	public static function select( $accept_types )
	{
		if ( !$type = self::$types[$accept_types[0]] )
		{
			$type = 'html';
		}

		return $type;
	}

	public static function is_ajax_request()
	{
		return (bool)$_SERVER['HTTP_X_REQUESTED_WITH'];
	}

	public static function format()
	{
		$accept = request::get_accept();
		return self::$types[$accept[0]] ? self::$types[$accept[0]] : 'html';
	}
}